package com.example.app.components


import android.graphics.Paint
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.size
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp

@Composable
fun BoxSample() {
    // align调整位置
//    Box() {
//        Box(modifier = Modifier
//            .size(300.dp)
//            .background(Color.Green)
//        )
//        Box(modifier = Modifier
//            .size(200.dp)
//            .background(Color.Red)
//            .align(Alignment.Center)
//        )
////           Text(text = "Text 2")
//    }
    BoxWithConstraints() {
        if (maxWidth < maxHeight) {
            // 竖屏模式
            Box(modifier = Modifier
                .size(300.dp)
                .background(Color.Green)
            )
        } else {
            // 横屏模式
            Box(modifier = Modifier
                .size(200.dp)
                .background(Color.Red)
                .align(Alignment.Center)
            )
        }
    }
}

@Preview(
    showSystemUi = true
)
@Composable
fun BoxSamplePreview() {
    BoxSample()
}

